﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using InnovaApp.Portals.MVC4Portal.Models;
using INNOVACALL.Framework.Common.MVCHelpers;
using InnovaApp.Layers.DataLayer;
using InnovaApp.Layers.ResourcesLayer.Properties;
using INNOVACALL.Framework.Common.CodeFormatting;
using INNOVACALL.Framework.Common;
using INNOVACALL.Framework.Common.Models;

namespace InnovaApp.Portals.MVC4Portal.Controllers
{
	public class Sample_SingleControl_TextBoxController : _Controllers_Base<TextBoxModel>
	{

		protected override void Initialize(System.Web.Routing.RequestContext requestContext)
		{
			base.eMethodBase = "InnovaApp.Portals.InnovaAppFrontOfficePortal.Controllers.Sample_SingleControl_TextBoxController";
			base.specificCssCollection = new string[] { "_FormCommon.css", "Views/Sample_SingleControl_TextBox.css", "ClientComponents/CodeFormatting/csharp.css", "ClientComponents/KendoUI/kendo.common.min.css", "ClientComponents/KendoUI/kendo.blueopal.min.css" };
			base.specificJSCollection = null;
			base.dynamicJSCollection = new string[] { "/ScriptsG/inoSample_SingleControl_TextBoxDynamic.js" };
			base.specificJqueryJSCollection = new string[] { "ClientComponents/KendoUI/kendo.web.min.js", "InnovacallJS/Sample_SingleControl_TextBox/Sample_SingleControl_TextBox.js" };
			base.externalCSS = null;
			base.Meta.Add(enMeta.Description, Resources.View_Sample_SingleControl_TextBox_Meta_Description);
			base.Meta.Add(enMeta.Keywords, Resources.View_Sample_SingleControl_TextBox_Meta_Keywords);
			base.Meta.Add(enMeta.Subject, Resources.View_Sample_SingleControl_TextBox_Meta_Subject);

			base.Initialize(requestContext);
		}

		[HttpGet, CacheManager(enCacheMode.NoCache)] //Manage your cache -- Authorize, Removed for search engine indexing
		public ActionResult Index()
		{
			//NEVER USES VIEW BAG AGAIN !
			//ViewBag.Message = "Modify this template to kick-start your ASP.NET MVC application.";
			{
				using (DataRepositories _dataContext = new DataRepositories())
				{
					base.InitView(
						Resources.View_Sample_SingleControl_TextBox_PageTitle,
						Resources.View_Sample_SingleControl_TextBox_PageMessage,
						specificCssCollection,
						specificJSCollection,
						dynamicJSCollection,
						specificJqueryJSCollection,
                        jsVariables,
						externalCSS,
						Meta,
						_dataContext,
						true
						);

					ContentData.TextValue = string.Empty;

					#region Involved code rendering
					INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel InvolvedSourceCode;
					INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel InvolvedSubSourceCode;
					ContentData.InvolvedCode = new InvolvedCodeModel();
					InvolvedSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();

					#region Views, partials & template editors
					InvolvedSourceCode.TabStripName = "Views, partials & template editors";
					InvolvedSourceCode.TabStripContent = string.Empty;
					InvolvedSourceCode.Language = enCodeLanguage._MultipleCodes;

					InvolvedSubSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Html, TabStripName = "View", TabStripContent = "/Views/Sample_SingleControl_TextBox/Index.cshtml" };
					InvolvedSourceCode.SubCodes.Add(InvolvedSubSourceCode);

					InvolvedSubSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Html, TabStripName = "Layout", TabStripContent = "/Views/Shared/_Layout.cshtml" };
					InvolvedSourceCode.SubCodes.Add(InvolvedSubSourceCode);


					ContentData.InvolvedCode.Add(InvolvedSourceCode);
					#endregion

					ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Controller", TabStripContent = "/Controllers/Sample_SingleControl_TextBoxController.cs" });

					ContentData.InvolvedCode.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Model", TabStripContent = "/Models/DropDownListModel.cs" });

					#region Javascripts
					InvolvedSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();
					InvolvedSourceCode.TabStripName = "Javascripts";
					InvolvedSourceCode.TabStripContent = string.Empty;
					InvolvedSourceCode.Language = enCodeLanguage._MultipleCodes;
					InvolvedSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Javascript, TabStripName = "View JS", TabStripContent = "/Scripts/InnovacallJS/Sample_SingleControl_TextBox/Sample_SingleControl_TextBox.js" });
					InvolvedSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Javascript, TabStripName = "Layout JS", TabStripContent = "/Scripts/InnovacallJS/_Layout/_Layout.js" });
					ContentData.InvolvedCode.Add(InvolvedSourceCode);
					#endregion

					#region CSS
					InvolvedSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();
					InvolvedSourceCode.TabStripName = "CSS";
					InvolvedSourceCode.TabStripContent = string.Empty;
					InvolvedSourceCode.Language = enCodeLanguage._MultipleCodes;
					InvolvedSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Css, TabStripName = "View CSS", TabStripContent = "/Content/Sample_SingleControl_TextBox.css" });
					InvolvedSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Css, TabStripName = "Form Common CSS", TabStripContent = "/Content/_FormCommon.css" });
					InvolvedSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Css, TabStripName = "Site (Layout) CSS", TabStripContent = "/Content/_Site.css" });
					ContentData.InvolvedCode.Add(InvolvedSourceCode);
					#endregion

					#region Generated client files
					InvolvedSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();
					InvolvedSourceCode.TabStripName = "Generated client files";
					InvolvedSourceCode.TabStripContent = string.Empty;
					InvolvedSourceCode.Language = enCodeLanguage._MultipleCodes;

					InvolvedSubSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();
					InvolvedSubSourceCode.TabStripName = "Javascript";
					InvolvedSubSourceCode.TabStripContent = string.Empty;
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Controller", TabStripContent = "/Controllers/ScriptsGController.cs" });
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Html, TabStripName = "View", TabStripContent = "/Views/ScriptsG/inoSample_SingleControl_TextBoxDynamic.cshtm" });
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.GeneratedJavascript, TabStripName = "Generated javascript", TabStripContent = "/ScriptsG/inoSample_SingleControl_TextBoxDynamic.js" });
					InvolvedSourceCode.SubCodes.Add(InvolvedSubSourceCode);

					InvolvedSubSourceCode = new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel();
					InvolvedSubSourceCode.TabStripName = "CSS";
					InvolvedSubSourceCode.TabStripContent = string.Empty;
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.cSharp, TabStripName = "Controller", TabStripContent = "/Controllers/CSSGController.cs" });
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.Html, TabStripName = "View", TabStripContent = "/Views/CSSG/site.cshtml" });
					InvolvedSubSourceCode.SubCodes.Add(new INNOVACALL.Framework.Common.Models.MetaModels.CodeFile_MetaModel() { Language = enCodeLanguage.GeneratedCss, TabStripName = "Generated CSS (from _site.css)", TabStripContent = "/CSSG/Site.css" });
					InvolvedSourceCode.SubCodes.Add(InvolvedSubSourceCode);

					ContentData.InvolvedCode.Add(InvolvedSourceCode);
					#endregion

					RenderCodeFiles(ContentData.InvolvedCode);
					#endregion
				}
				return View(ContentData);
			}
		}

		/// <summary>
		/// Error is catched automatically
		/// </summary>
		/// <param name="Id"></param>
		/// <returns></returns>
		[HttpPost, CacheManager(enCacheMode.NoCache)] //Manage your cache -- Authorize, Removed for search engine indexing
		public JsonResult ReceiveTextBoxContent(string typedText)
		{
			JsonResult toReturn = new JsonResult { JsonRequestBehavior = JsonRequestBehavior.AllowGet };
			string htmlResult;
			//using (DataRepositories _dataContext = new DataRepositories())
			//{
			htmlResult = Server.HtmlEncode("You typed : " + typedText);
			toReturn.Data = new { @success = true, @divToUpdate = "#divDescription", @htmlResult = htmlResult };
			//}
			return toReturn;
		}
	}
}
